﻿#region Using References

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using Beaker.OpenCube.Game;
using Beaker.OpenCube.Mapping;
using Beaker.OpenCube.Nbt;
using Beaker.OpenCube.Specs.Builders;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#endregion

namespace Beaker.OpenCube.Specs.Mapping
{
	[ExcludeFromCodeCoverage]
	[TestClass]
	public class MappingSpecs
	{
		#region RegularMapping

		[TestMethod]
		public void EmptyDictionaryMapsToNull()
		{
			// arrange
			IDictionary<string, object> dict = new DictionaryBuilder()
				.Build();
			var mapper = new Mapper<Object>();

			// act
			object o = mapper.MapDictionary( dict );

			// assert
			o.Should().BeNull();
		}

		#endregion
		#region ExpandoMapping

		[TestMethod]
		public void UnmappendIntWillMappedToExpandoProperty()
		{
			// arrange
			IDictionary<string, object> dict = new DictionaryBuilder()
				.With( "MyInt", 476892 )
				.Build();
			var mapper = new Mapper<ObservableExpandoObject>();

			// act
			dynamic obj = mapper.MapDictionary( dict );

			// assert
			( (int)obj.MyInt ).Should().Be( 476892 );
		}

		[TestMethod]
		public void UnmappendNestedDictionaryWillMappedToNestedExpandoObject()
		{
			// arrange
			IDictionary<string, object> innerDict = new DictionaryBuilder()
				.With( "SomeString", "FooBar" )
				.Build();
			IDictionary<string, object> dict = new DictionaryBuilder()
				.With( "MyCompound", innerDict )
				.Build();
			var mapper = new Mapper<ObservableExpandoObject>();

			// act
			dynamic obj = mapper.MapDictionary( dict );

			// assert
			dynamic innerObject = obj.MyCompound;
			( (string)innerObject.SomeString ).Should().Be( "FooBar" );
		}

		#endregion
	}
}
